<template>
  <div class="contentBox">
    <el-row>
      <el-col :span="3"><div class="grid-content">栏目内容:</div></el-col>
      <el-col :span="21"
        ><div class="grid-content">
          <quill-editor
            :options="editorOption"
            v-model="column_content"
          ></quill-editor></div
      ></el-col>
    </el-row>
    <el-form>
      <el-form-item class="btn">
        <el-button type="primary" @click="submitForm()">保存</el-button>
        <el-button @click="cancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      column_content: "",
      editorOption: {
        modules: {
          toolbar: [
            [
              { header: 1 },
              "bold",
              "italic",
              "color",
              "background",
              { list: "bullet" },
              "video",
              "image",
              "align",
            ], // toggled buttons
            ["blockquote", "code-block"],
          ],
        },
        placeholder: "在这里编辑页面",
      },
    };
  },
  methods: {
    submitForm() {
        this.$confirm("是否保存内容?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(async () => {
              let id = this.$store.state.columnId ? this.$store.state.columnId : window.localStorage.getItem("columnId")
              // console.log(id);
              let obj = {
                  columnId: id*1,
                  content: this.column_content
              }
            let { meta: {status} } = await this.$http.getContent(obj)
            if (status == 200) {
                window.localStorage.removeItem("columnId")
                this.$router.push("/column")
                this.$message({
                  type: "success",
                  message: "内容设置成功",
                });
            }
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "保存失败",
            });
          });
    },
    cancel() {
        this.$router.push('/column')
    },
  },
};
</script>

<style scoped lang="less">
.contentBox {
  min-width: 700px;
  max-width: 900px;
  margin-left: 100px;
}
.el-form {
  margin-top: 150px;
  text-align: right;
  .el-button {
    margin-left: 50px;
    height: 35px;
  }
}
.quill-editor {
  height: 600px !important;
}
.ql-container,
.ql-editor {
  height: 80% !important;
}
.ql-editor {
  overflow: auto;
}
.ql-snow .ql-editor img {
  width: 300px;
}
</style>
